<?php
class Auth_IndexController extends Zend_Controller_Action {
	public function indexAction() {
		$this->view->title = "admin index";
	}
	
	public function loginAction() {
		$auth = Zend_Auth::getInstance ();
		if ($this->_request->isPost ()) {
			$user = $this->_request->getPost ( 'name' );
			$pass = $this->_request->getPost ( 'password' );
			 
			$db = $this->getInvokeArg ( 'bootstrap' )->getResource ( 'db' );
			$adapter = new Zend_Auth_Adapter_DbTable ( $db );
			$adapter->setTableName ( 'users' )
			->setIdentityColumn ( 'name' )
			->setCredentialColumn ( 'password' );			
			$adapter->setIdentity ( $user )
			->setCredential ( md5 ( $pass ) );	
					
			$result = $auth->authenticate ( $adapter );
			
			if ($result->isValid ()) {
				$auth->clearIdentity ();
				$auth->getStorage ()->write ( $adapter->getResultRowObject ()->id );
				//if (! empty ( $_SERVER ['HTTP_REFERER'] ))
				//	header ( 'Location: ' . $_SERVER ['HTTP_REFERER'] );
				//else
				//	$this->_redirect ( '/' );
				var_dump($result);
				$this->_helper->redirector->gotoSimple('list', 'categories', 'files');
			
			}			 
		}	
	}
}
